package com.gidgabs.config;

import com.gidgabs.common.interceptor.AuthorizationInterceptorApi;
import com.gidgabs.common.resolver.LoginUserHandlerMethodArgumentResolverApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.List;

/**
 * MVC配置
 */
@Configuration
public class WebMvcConfigApi extends WebMvcConfigurerAdapter {

    @Autowired
    private AuthorizationInterceptorApi authorizationInterceptorApi;

    @Autowired
    private LoginUserHandlerMethodArgumentResolverApi loginUserHandlerMethodArgumentResolverApi;


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authorizationInterceptorApi).addPathPatterns("/api/**");
    }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        argumentResolvers.add(loginUserHandlerMethodArgumentResolverApi);
    }
}
